var express = require('express');
var router = express.Router();
//导入用于生成JWT字符串的包
const jwt = require('jsonwebtoken');

const config = require('../config');


router.post('/login', function (req, res) {
    const userInfo = req.body;
    if (userInfo.username === "admin" && userInfo.password === "123456") {
        // 登录成功
        const tokenStr = jwt.sign({ username: userInfo.username }, config.secretKey, { expiresIn: '1h' });
        res.send({
            status: 200,
            msg: '登录成功',
            token: tokenStr //要发送给客户端的token字符串
        })
    } else {
        res.send({
            status: 400,
            msg: "用户名或者密码不正确！"
        })
    }
});
module.exports = router;